<template>
  <div class="login-container">
    <el-form label-position="left" label-width="0px" class="demo-ruleForm login-page">
      <h3 class="title" style="margin-left:100px ">考研资料分享系统</h3>
      <el-form-item prop="telphone">
        <el-input type="text" v-model="form.telphone" auto-complete="off" placeholder="手机号/工号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="form.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-radio v-model="form.utype" label="0">普通用户</el-radio>
        <el-radio v-model="form.utype" label="1">管理员</el-radio>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" @click="login">登录</el-button>
      </el-form-item>
      <el-form-item>
        <el-link type="primary">
          <i class="el-icon-lock" type="primary" />忘记密码？
        </el-link>
        <el-link type="primary" href="/register" style="margin-left:200px ">注册</el-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // logining: false,
      form: {
        telphone: "",
        password: "",
        utype: "0"
      }
    };
  },
  methods: {
    login() {
      this.$http.post("user/login", this.form).then(result => {
        if (result.body.flag == true) {
          console.log(result.body.data);
          var userId = result.body.data.id;
          var utype=result.body.data.utype;
          //保存到vuex
          this.$store.commit("useid", userId);
          this.$store.commit("utype", utype);
          //弹出登录成功
          this.$message.success(result.body.message);
          //成功跳转路径
          if (this.form.utype == 0) {
            this.$router.push("/home");
          } else if (this.form.utype == "1") {
            this.$router.push("/admin");
          }
        } else {
          // 弹出通知框提示登录失败信息
          this.$message.error(result.body.message);
        }
      });
    }
  }
};
</script>

<style>
.login-container {
  width: 100%;
  height: 100%;
}
.login-page {
  -webkit-border-radius: 5px;
  border-radius: 5px;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
label.el-checkbox.rememberme {
  margin: 0px 0px 15px;
  text-align: left;
}
</style>